//
//  DoctorsApplyCell.m
//  International_Hospital
//
//  Created by 统杰李 on 16/7/6.
//  Copyright © 2016年 LiYiLin. All rights reserved.
//

#import "DoctorsApplyCell.h"

@interface DoctorsApplyCell ()

//病人
@property (nonatomic, strong)UILabel *userNameLable;

//什么病
@property (nonatomic, strong)UILabel *diseaseLabel;

//就诊时间
@property (nonatomic, strong)UILabel *timeLabel;

//医生名
@property (nonatomic, strong)UILabel *doctorNameLabel;

//主任医生
@property (nonatomic, strong)UILabel *archiater;
//医院
@property (nonatomic, strong)UILabel *hospitalLabel;

////就诊状态视图
@property (nonatomic, strong)UIView *statusView;

//就诊状态
@property (nonatomic, strong)UILabel *statusLabel;

////中间线
@property (nonatomic, strong)UIView *centerLineView;

@end

@implementation DoctorsApplyCell

- (void)setStatuStr:(NSString *)statuStr{
    
    _statuStr = statuStr;
    self.statusLabel.text = statuStr;
    
}

- (void)setModel:(DoctorApplyModel *)model{
    
    _model = model;
    
    self.userNameLable.text = @"张先生";
    
    self.doctorNameLabel.text = model.doctor_name;
    
    self.diseaseLabel.text = @"心理疾病";
    
    self.archiater.text = @"主任医师";
    
    self.hospitalLabel.text = model.doctor_hospital_name;
    
    //    self.timeLabel.text = @"就诊:2016/07/04";
    //时间
    NSDate *currentdate = [NSDate date];
    
    NSDateFormatter *fm = [[NSDateFormatter alloc] init];
    
    fm.dateFormat = @"MM-dd上午";
    
    NSString *dateString = [fm stringFromDate:currentdate];
    
    fm.dateFormat = @"HH";
    
    NSString *dateString2 = [fm stringFromDate:currentdate];
    
    fm.dateFormat = @"MM-dd下午";
    
    NSString *dateString3 = [fm stringFromDate:currentdate];
    
    
    if ([dateString2 intValue]>= 0 && [dateString2 intValue]<=12) {
        self.timeLabel.text = [NSString stringWithFormat:@"就诊:%@",dateString];
    }else{
        self.timeLabel.text = [NSString stringWithFormat:@"就诊:%@",dateString3];
    }
 
}

#pragma mark
#pragma mark - initWithStyle
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
        
    }
    
    return self;
    
}

#pragma mark
#pragma mark - 初始化界面
- (void)setupUI{
    
    //给label赋值
    self.userNameLable = [self addChildLabel];
    self.doctorNameLabel = [self addChildLabel];
    self.diseaseLabel = [self addChildLabel];
    self.timeLabel = [self addChildLabel];
    self.archiater = [self addChildLabel];
    self.hospitalLabel = [self addChildLabel];
    self.statusLabel = [self addChildLabel];
    
    //给审核设置白色,居中显示
    self.statusLabel.textAlignment = NSTextAlignmentCenter;
    
    //添加
    [self.contentView addSubview:self.userNameLable];
    [self.contentView addSubview:self.diseaseLabel];
    [self.contentView addSubview:self.timeLabel];
    [self.contentView addSubview:self.doctorNameLabel];
    [self.contentView addSubview:self.archiater];
    [self.contentView addSubview:self.hospitalLabel];
    [self.contentView addSubview:self.statusView];
    [self.statusView addSubview:self.statusLabel];
    [self.contentView addSubview:self.centerLineView];
    
    //设置约束
    [self.userNameLable makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.contentView.left).offset(20);
        
        make.top.equalTo(self.contentView.top).offset(20);
        
        make.width.equalTo(55);
        
    }];
    
    [self.doctorNameLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.userNameLable.left);
        make.bottom.equalTo(self.contentView.bottom).offset(-20);
        make.right.equalTo(self.userNameLable.right);
    }];
    
    [self.diseaseLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.userNameLable.right).offset(8);
        make.top.equalTo(self.userNameLable.top);
        
        make.width.equalTo(70);
    }];
    
    [self.timeLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.diseaseLabel.right).offset(8);
        make.top.equalTo(self.diseaseLabel.top);
        
    }];
    
    [self.archiater makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.doctorNameLabel.bottom);
        make.left.equalTo(self.diseaseLabel.left);
        make.right.equalTo(self.diseaseLabel.right);
    }];
    
    [self.hospitalLabel makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.archiater.bottom);
        make.left.equalTo(self.timeLabel.left);
        make.right.equalTo(self.statusView.left).offset(-5);
    }];
    
    [self.statusView makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.right).offset(-10);
        make.centerY.equalTo(self.contentView.centerY);
        make.width.equalTo(56);
        make.height.equalTo(56);
    }];
    
    [self.statusLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.equalTo(self.statusView);
    }];
    
    [self.centerLineView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.userNameLable.left);
        make.centerY.equalTo(self.contentView);
        make.height.equalTo(3);
        make.width.equalTo(SCREEN_WIDTH).offset(SCREEN_WIDTH -85);
    }];
}

#pragma mark
#pragma mark - 创建label的方法
-(UILabel *)addChildLabel{
    UILabel *label = [[UILabel alloc] init];
    
    label.textColor = [UIColor blackColor];
    
    if ([UIScreen mainScreen].bounds.size.width == 320) {
        label.font = [UIFont systemFontOfSize:12];
    }else{
        label.font = [UIFont systemFontOfSize:17];
    };
    
    return label;
    
}

#pragma mark
#pragma mark - 设置审核view
-(UIView *)statusView{
    if (_statusView == nil) {
        
        _statusView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 56, 56)];
        
        //设置圆角
        _statusView.layer.cornerRadius = 28;
        
        
        _statusView.backgroundColor = [UIColor colorWithRed:34 / 255.0 green:183 / 255.0 blue:200 / 255.0 alpha:1];
        
        
        _statusView.layer.masksToBounds = YES;
        
    }
    return _statusView;
}

#pragma mark
#pragma mark - 中间线view
-(UIView *)centerLineView{
    if (_centerLineView == nil) {
        _centerLineView = [[UIView alloc] init];
        _centerLineView.backgroundColor = [UIColor colorWithRed:34 / 255.0 green:183 / 255.0 blue:200 / 255.0 alpha:1];
    }
    return _centerLineView;
}

@end
